<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Title</title>
<!--    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>-->
<!--    <script src="https://unpkg.com/axios/"></script>-->
    <script type="text/javascript" src="/axios.min.js"></script>
</head>
<body>
<h1>看我</h1>
<hr>
<script>
    /*
    响应头：Content-Type: application/json;charset=UTF-8
    响应数据：{"code":200,"method":"GET","data":{"id":0,"name":null},"ip":"0:0:0:0:0:0:0:1"}
    */
    function g1() {
        axios.get('/api/show?id=123&name=李青')
            .then(res=>{
                console.log(res.data.data)
            })
            .catch(err=>{
                console.log(err)
            })
    }
    g1()

    // 和上边一样
    function g2() {
        axios({
            method: 'get',
            url: '/api/show',
            param: {id: 55, name: '张三'}
        }).then(res => {
            console.log(res.data.data)
            console.log(res.data.method)
        }).then(err=>{
            console.log(err)
        })
    }

    function g3(){
// 可选地，上面的请求可以这样做
        axios.get('/api/show', {
            params: {ID: 12345}
        }).then(function (response) {
            console.log(response);
        })
        .catch(function (error) {
            console.log(error);
        });
    }

    function p1(){
        // 请求负载接值，需要加@RequestBody
        axios.post('/api/show',  {
            id: 77,
            name: '令人'
        })
            .then(function (response) {
                console.log(response.data);
            })
            .catch(function (error) {
                console.log(error);
            });
    }

    function p2() {
        // 发送 POST 请求
        axios({
            method: 'post',
            url: '/api/show',
            headers: {'Content-Type': 'application/json;charset=utf-8'},

            data: {
                id: 'Fred',
                name: 'Flintstone'
            }
        }).then(function (response) {
            console.log(response.data.data);
        })
            .catch(function (error) {
                console.log(error);
            });
    }


</script>
</body>
</html>
